package com.xbjtech.ticketsystem.controller;

import com.xbjtech.ticketsystem.model.Resource;
import com.xbjtech.ticketsystem.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author leejun.happy@gmail.com
 * @created 2019-03-02
 */
@Controller
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    ResourceService resourceService;

    @RequestMapping("/list")
    public String list() {
        return "/resource/list";
    }

    @GetMapping("/page")
    @ResponseBody
    public Map<String, Object> page() {
        Example example = new Example(Resource.class);
        List<Resource> info = resourceService.selectByExample(example);
        Map<String, Object> result = new HashMap<>();
        result.put("total", info.size());
        result.put("rows", info);
        return result;
    }

    @GetMapping("/insert")
    @ResponseBody
    public String abc() {
        Resource r = new Resource();
        r.setName("系统管理");
        r.setIcon("&#xe674;");
        r.setParentId(0);
        //r.setPermission("user:list");
        r.setType(0);
        //r.setUrl("/user/list");
        resourceService.insertWithoutPrimaryKey(r);
        return "hello";

    }

}
